package com.lntu.meeting.controller;

import com.lntu.meeting.mapper.FindDayMapper;
import com.lntu.meeting.pojo.Notes;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class FindDayController {
    @Autowired
    private FindDayMapper findDayMapper;

    @RequestMapping("/")
    public String findDay(@RequestBody String date) {
        if (date == null) {
            return "isNull";
        }
        String flag = "500";
        String res = "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date currentTime = new Date();
        String format = simpleDateFormat.format(currentTime);
        if (format.equals(date)) {
            List<Notes> dayList = findDayMapper.findDayList(date);
            if (dayList.size() > 0) {
                flag = "200";
                Map<String, Object> resMap = new HashMap();
                resMap.put("flag", flag);
                resMap.put("data", dayList);
                res = JSON.JSON.toJSONString(resMap);
            }
        } else {
            Map<String, Object> resMap = new HashMap();
            resMap.put("flag", flag);
            res = JSON.JSON.toJSONString(resMap);
        }
        return res;

    }
}
